package ebcs.scan.controller.needCtr;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;

import java.util.ArrayList;


import java.text.DecimalFormat;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.serializer.BigDecimalCodec;

import ebcs.database.bean.BsGoal;
import ebcs.database.bean.BsNeedInfor;
import ebcs.database.bean.BsNeedStage;
import ebcs.database.bean.BsNeedTime;
import ebcs.database.bean.BsOnlineNeed;
import ebcs.database.bean.BsProTeamInfor;
import ebcs.database.bean.BsSaleNeed;
import ebcs.database.bean.BsUserInfor;
import ebcs.database.bean.BsUserNeedRel;
import ebcs.database.bean.FaceToFace;
import ebcs.database.bean.NeedConversion;
import ebcs.database.bean.RpProjectMoneyBean;
import ebcs.database.bean.RpUserReportBean;
import ebcs.database.service.BsProTeamServiceImp;
import ebcs.database.service.BsUserInforServiceImp;
import ebcs.database.service.BsUserNeedServiceImp;
import ebcs.database.service.ReportServiceImp;
import ebcs.scan.bean.common.ExcleEntity;
import ebcs.scan.common.utils.ExportDataUtil;
import ebcs.scan.common.utils.StringUtil;
import ebcs.scan.controller.batch.BatchManagerCtrl;
import jplat.core.trans.JAppBaseService;
import jplat.core.trans.JAppContext;
import jplat.core.trans.JAppContextFactory;
import jplat.error.exception.JSystemException;
import jplat.error.exception.JTransException;
import jplat.tools.string.DateUtil;
import jplat.tools.string.JRandomUtil;
 

/***
 * 需求管理
 * @author chenzhuo
 * @comment
 */
@Controller
public class NeedManagerCtrl extends JAppBaseService
{
	private Logger logger = Logger.getLogger(NeedManagerCtrl.class);
	protected JAppContextFactory serviceFactory = new JAppContextFactory();

	@Autowired
	public BatchManagerCtrl batch;
	//数据库库服务.
	@Autowired 
	public BsUserInforServiceImp userInforService ; 
	@Autowired
	private BsUserNeedServiceImp userNeedService;
	@Autowired
	public BsProTeamServiceImp teamService;
	@Autowired
	public ReportServiceImp reportService;
 
	
	public static String CHARSET_ENCODING = "UTF-8";
	
	/**
	 * 新增需求功能 
	 */
	@RequestMapping("/page/need/doMakeNeed.do")
	public String doMakeNeed( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsUserInfor user = context.getUserInfo();
		request.setAttribute("userBean", user);
		return "frame/html/need/makeNeedInfor";
	}
	
	/**
	 * 新增需求功能 (后台)
	 */
	@RequestMapping("/page/need/backdoMakeNeedback.do")
	public String doMakeNeedBack( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsUserInfor user = context.getUserInfo();
		String GroupNo = user.getProTeamNo().substring(0, 5);
		List<BsProTeamInfor> teanList = this.teamService.searchProTeanListByGroupNo(GroupNo);
		request.setAttribute("teanList", teanList);
		request.setAttribute("userBean", user);
		return "frame/html/need/makeNeedInforBlck";
	}
	
	   
	/**
	 * 修改需求功能 
	 */
	@RequestMapping("/page/need/{needId}/doUpdateNeedInfor.do")
	public String doUpdateNeedInfor( HttpServletRequest request,HttpServletResponse response ,@PathVariable String needId) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
  		List<BsNeedInfor> needList = this.userInforService.selectByNeedId(needId);
 		request.setAttribute("needBean", needList.get(0));
		return "frame/html/need/updateNeedInfor"; 
	}
	
	/**
	 * 修改需求计划 
	 */
	@RequestMapping("/page/need/{needId}/updateNeedstage.do")
	public String updateNeedstage( HttpServletRequest request,HttpServletResponse response ,@PathVariable String needId) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsNeedStage req=new BsNeedStage();
		req.setNeedId(needId);
		List<BsNeedStage> needList = this.userNeedService.selectBsNeedStage(req);
		if(needList.size()>0) {
 		request.setAttribute("needBean", needList.get(0));
 		return "frame/html/need/updateNeedstage"; 
		}else {
			List<BsNeedInfor> needList2 = this.userInforService.selectByNeedId(needId);
	 		request.setAttribute("needBean", needList2.get(0));
	 		return "frame/html/need/addNeedstage";
		}
	
	}
	
	/**
	 * 新增需求计划 
	 * @param request
	 * @param response
	 * @throws JTransException
	 * @throws JSystemException
	 */
	@RequestMapping("/page/need/addNeedstage.do")
	public void addNeedstage( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
 		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
 		BsNeedStage emm = context.obtainReqModel(BsNeedStage.class);
 		//3、判断需求计划日期符合顺序
  		if(emm.getNeed_Brewing().compareTo(emm.getNeed_Analysis())>0&&(StringUtil.isNotEmpty(emm.getNeed_Analysis()))){
  			throw new  JTransException("1001","分析时间必须在酝酿时间后面！");
  		} 
  		if(emm.getNeed_Analysis().compareTo(emm.getNeed_Confirm())>0&&(StringUtil.isNotEmpty(emm.getNeed_Confirm()))){
  			throw new  JTransException("1001","确认时间必须在分析时间后面！");
  		} 
  		if(emm.getNeed_Confirm().compareTo(emm.getNeed_Review())>0&&(StringUtil.isNotEmpty(emm.getNeed_Review()))){
  			throw new  JTransException("1001","评审时间必须在确认时间后面！");
  		} 
  		if(emm.getNeed_Review().compareTo(emm.getTechnical_Review())>0&&(StringUtil.isNotEmpty(emm.getTechnical_Review()))){
  			throw new  JTransException("1001","技术评审时间必须在需求评审时间后面！");
  		} 
  		if(emm.getTechnical_Review().compareTo(emm.getDevelop_Joint())>0&&(StringUtil.isNotEmpty(emm.getDevelop_Joint()))){
  			throw new  JTransException("1001","联调时间必须在技术评审时间后面！");
  		} 
  		if(emm.getDevelop_Joint().compareTo(emm.getSit_Test())>0&&(StringUtil.isNotEmpty(emm.getSit_Test()))){
  			throw new  JTransException("1001","sit时间必须在联调时间后面！");
  		} 
  		if(emm.getSit_Test().compareTo(emm.getUat_Test())>0&&(StringUtil.isNotEmpty(emm.getUat_Test()))){
  			throw new  JTransException("1001","uat时间必须在sit时间后面！");
  		} 
  		if(emm.getUat_Test().compareTo(emm.getNeed_Online())>0&&(StringUtil.isNotEmpty(emm.getNeed_Online()))){
  			throw new  JTransException("1001","上线时间必须在uat时间后面！");
  		}
 		emm.setRouid(JRandomUtil.getUUID());
 		emm.setBack_Review_Old(emm.getBack_Review());
 		emm.setDevelop_Joint_Old(emm.getDevelop_Joint());
 		emm.setNeed_Analysis_Old(emm.getNeed_Analysis());
 		emm.setNeed_Brewing_Old(emm.getNeed_Brewing());
 		emm.setNeed_Confirm_Old(emm.getNeed_Confirm());
 		emm.setNeed_Online_Old(emm.getNeed_Online());
 		emm.setNeed_Review_Old(emm.getNeed_Review());
 		emm.setSit_Test_Old(emm.getSit_Test());
 		emm.setTechnical_Review_Old(emm.getTechnical_Review());
 		emm.setUat_Test_Old(emm.getUat_Test());
 		emm.setNeed_State("00");
 		userNeedService.insertBsNeedStage(emm);
 		Map rspModel = new HashMap();
		context.buildAppResponse(rspModel);
	}
	
	
	
	/**
	 * 新增目标功能 
	 */
	@RequestMapping("/page/need/addgoal.do")
	public String addgoal( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsUserInfor user = context.getUserInfo();
		String GroupNo = user.getProTeamNo().substring(0, 5);
		List<BsProTeamInfor> teanList = this.teamService.searchProTeanListByGroupNo(GroupNo);
		request.setAttribute("teanList", teanList);
		request.setAttribute("userBean", user);
		return "frame/html/need/makeGoal";
	}
	
	
	
	/**
	 * 新增目标 
	 * @param request
	 * @param response
	 * @throws JTransException
	 * @throws JSystemException
	 */
	@RequestMapping("/page/need/doaddgoal.do")
	public void doaddgoal( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
 		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
 		BsGoal emm = context.obtainReqModel(BsGoal.class);
 		emm.setRouid(JRandomUtil.getUUID());
 		String  str=emm.getProTeamNo().substring(0, 5);
 		emm.setProGroupNo(str);
 		userNeedService.insertteamgoal(emm);
 		List<BsGoal> needList1 = this.userNeedService.selectgoal(emm);
 		List<BsGoal> needList2 = this.userNeedService.selectteamgoalsum(emm);
 		BsGoal re=	needList2.get(0);
 		if(needList1.size()>0) {
 			BsGoal req=	needList1.get(0);
 			req.setGoal(re.getGoal());
 			userNeedService.updategoal(req);
 		}else {
 			emm.setGoal(re.getGoal());
 			emm.setRouid(JRandomUtil.getUUID());
 			userNeedService.insertgoal(emm);
 		}
 		Map rspModel = new HashMap();
		context.buildAppResponse(rspModel);
	}
	
	
	
	/**
	 * 删除目标信息
	 */
	@RequestMapping("/page/need/dodeletegoal.do")
	public void dodeletegoal( HttpServletRequest request,HttpServletResponse response) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsGoal bsUserNeedRel = context.obtainReqModel(BsGoal.class);
		userNeedService.deleteteamgoal(bsUserNeedRel.getRouid());
		String  str=bsUserNeedRel.getProTeamNo().substring(0, 5);
		bsUserNeedRel.setProGroupNo(str);
		List<BsGoal> needList2 = this.userNeedService.selectteamgoalsum(bsUserNeedRel);
		List<BsGoal> needList1 = this.userNeedService.selectgoal(bsUserNeedRel);
		BsGoal re=	needList2.get(0);
		BsGoal req=	needList1.get(0);
		if(re!=null) {
		req.setGoal(re.getGoal());
		}else {
			req.setGoal("0");
		}
		userNeedService.updategoal(req);
		Map rspMode2 = new HashMap();
		
        context.buildAppResponse(rspMode2); 
	}

	
	/**
	 * 修改需求计划 功能 
	 */
	@RequestMapping("/page/need/doupdateNeedstage.do")
	public void doupdateNeedstage( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsNeedStage req = context.obtainReqModel(BsNeedStage.class);
		//3、判断需求计划日期符合顺序
  		if(req.getNeed_Brewing().compareTo(req.getNeed_Analysis())>0&&(StringUtil.isNotEmpty(req.getNeed_Analysis()))){
  			throw new  JTransException("1001","分析时间必须在酝酿时间后面！");
  		} 
  		if(req.getNeed_Analysis().compareTo(req.getNeed_Confirm())>0&&(StringUtil.isNotEmpty(req.getNeed_Confirm()))){
  			throw new  JTransException("1001","确认时间必须在分析时间后面！");
  		} 
  		if(req.getNeed_Confirm().compareTo(req.getNeed_Review())>0&&(StringUtil.isNotEmpty(req.getNeed_Review()))){
  			throw new  JTransException("1001","评审时间必须在确认时间后面！");
  		} 
  		if(req.getNeed_Review().compareTo(req.getTechnical_Review())>0&&(StringUtil.isNotEmpty(req.getTechnical_Review()))){
  			throw new  JTransException("1001","技术评审时间必须在需求评审时间后面！");
  		} 
  		if(req.getTechnical_Review().compareTo(req.getDevelop_Joint())>0&&(StringUtil.isNotEmpty(req.getDevelop_Joint()))){
  			throw new  JTransException("1001","联调时间必须在技术评审时间后面！");
  		} 
  		if(req.getDevelop_Joint().compareTo(req.getSit_Test())>0&&(StringUtil.isNotEmpty(req.getSit_Test()))){
  			throw new  JTransException("1001","sit时间必须在联调时间后面！");
  		} 
  		if(req.getSit_Test().compareTo(req.getUat_Test())>0&&(StringUtil.isNotEmpty(req.getUat_Test()))){
  			throw new  JTransException("1001","uat时间必须在sit时间后面！");
  		} 
  		if(req.getUat_Test().compareTo(req.getNeed_Online())>0&&(StringUtil.isNotEmpty(req.getNeed_Online()))){
  			throw new  JTransException("1001","上线时间必须在uat时间后面！");
  		} 
		req.setNeed_State("00");
		this.userNeedService.updateBsNeedStage(req);
		req.setRouid(JRandomUtil.getUUID());
		req.setUpdateTime(DateUtil.getSystemTimeBySomeFormat("yyyyMMdd"));
		this.userNeedService.insertHisStage(req);
		Map rsModel = new HashMap();
		context.buildAppResponse(rsModel);
	}
	
	
	/**
	 * 上线记录
	 */
	@RequestMapping("/page/need/{needId}/{needTime}/doUpdateOnlineNeed.do")
	public String doUpdateOnlineNeed( HttpServletRequest request,HttpServletResponse response ,@PathVariable String needId,@PathVariable String needTime) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
  		List<BsOnlineNeed> needList = this.userNeedService.selectBsOnlineNeedById(needId);
 		List<BsNeedInfor> needList1 = this.userInforService.selectByNeedId(needId);
 		double nTime=Double.parseDouble(needTime);
 		double  now_nTime=0;
 		for(BsOnlineNeed bs:needList) {
 			now_nTime+=Double.parseDouble(bs.getNeedTime());
 		}
 		double  return_nTime1=(nTime-now_nTime);
 		 BigDecimal bd = new BigDecimal(return_nTime1);
 		Double return_nTime = bd.setScale(6,BigDecimal.ROUND_HALF_UP).doubleValue();
 		request.setAttribute("needList", needList);
 		request.setAttribute("needBean", needList1.get(0));
 		request.setAttribute("now_nTime", now_nTime);
 		request.setAttribute("nTime", nTime);
 		request.setAttribute("return_nTime", return_nTime);
		return "frame/html/need/updateOnlineNeed"; 
	}
	
	
	/**
	 * 新增上线
	 */
	@RequestMapping("/page/need/updateOnlineNeed.do")
	public void updateOnlineNeed( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsOnlineNeed req = context.obtainReqModel(BsOnlineNeed.class);
		String rouid = UUID.randomUUID().toString().replaceAll("-", "");
		req.setRouid(rouid);
		userNeedService.insertBsOnlineNeed(req);
		Map rsModel = new HashMap();
		context.buildAppResponse(rsModel);
	}
	
	
	
	/**
	 * 删除上线
	 */
	@RequestMapping("/page/need/dodeleteOnlineNeed.do")
	public void dodeleteOnlineNeed( HttpServletRequest request,HttpServletResponse response) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsOnlineNeed bsUserNeedRel = context.obtainReqModel(BsOnlineNeed.class);
		userNeedService.deleteBsOnlineNeed(bsUserNeedRel.getRouid());

		Map rspMode2 = new HashMap();
		
        context.buildAppResponse(rspMode2); 
	}
	
	
	
	/**
	 * 录入销售系统
	 */
	@RequestMapping("/page/need/{needId}/{needTime}/doUpdateSaleNeed.do")
	public String doUpdateSaleNeed( HttpServletRequest request,HttpServletResponse response ,@PathVariable String needId,@PathVariable String needTime) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
  		List<BsSaleNeed> needList = this.userNeedService.selectBsSaleNeedById(needId);
  		//String sum_money=(Double.parseDouble(needTime)/22/8*2.5)+"";
 		
  		BigDecimal s_money=new BigDecimal(needTime);
  		double sum_money1= s_money.divide(new BigDecimal(22),6,RoundingMode.HALF_UP).divide(new BigDecimal(8),6,RoundingMode.HALF_UP).multiply(new BigDecimal(2.5)).doubleValue();
  		BigDecimal bb = new BigDecimal(sum_money1);
		Double sum_money = bb.setScale(6,BigDecimal.ROUND_HALF_UP).doubleValue();
  		List<BsNeedInfor> needList1 = this.userInforService.selectByNeedId(needId);
 		
 		double  now_money=0;
 		for(BsSaleNeed bs:needList) {
 			now_money+=Double.parseDouble(bs.getMoney());
 		}
 		double  return_money1=(sum_money-now_money);
		 BigDecimal bd = new BigDecimal(return_money1);
		Double return_money = bd.setScale(6,BigDecimal.ROUND_HALF_UP).doubleValue();
 		request.setAttribute("needList", needList);
 		request.setAttribute("needBean", needList1.get(0));
 		request.setAttribute("now_money", now_money);
 		request.setAttribute("sum_money", sum_money);
 		request.setAttribute("return_money", return_money);
		return "frame/html/need/updateSaleNeed"; 
	}
	
	
	/**
	 * 新增录入销售系统
	 */
	@RequestMapping("/page/need/updateSaleNeed.do")
	public void updateSaleNeed( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsSaleNeed req = context.obtainReqModel(BsSaleNeed.class);
		String rouid = UUID.randomUUID().toString().replaceAll("-", "");
		req.setRouid(rouid);
		userNeedService.insertSaleNeed(req);
		Map rsModel = new HashMap();
		context.buildAppResponse(rsModel);
	}
	
	/**
	 * 删除销售 
	 */
	@RequestMapping("/page/need/dodeleteSale.do")
	public void dodeleteSale( HttpServletRequest request,HttpServletResponse response) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsSaleNeed bsUserNeedRel = context.obtainReqModel(BsSaleNeed.class);
		userNeedService.deleteSaleNeed(bsUserNeedRel.getRouid());

		Map rspMode2 = new HashMap();
		
        context.buildAppResponse(rspMode2); 
	}
	
	
	
	/**
	 * 删除需求功能 
	 */
	@RequestMapping("/page/need/dodeleteInfor.do")
	public void dodeleteInfor( HttpServletRequest request,HttpServletResponse response) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsUserNeedRel bsUserNeedRel = context.obtainReqModel(BsUserNeedRel.class);
		List<BsUserNeedRel> needList1 = userNeedService.selectByNeedId(bsUserNeedRel.getRouid());
		String tishi;
		if(needList1.size()==0){
			userNeedService.deleteInfor(bsUserNeedRel.getRouid());
			tishi="删除成功";
		}else{
			tishi="请先删除报功记录";
		}
		request.setAttribute("tishi", tishi);
		Map rspModel = new HashMap();
		rspModel.put("tishi", tishi);
        context.buildAppResponse(rspModel); 
	}
	/**
	 * 需求展示 
	 */
	@RequestMapping("/page/need/doShowNeedInfor.do")
	public String doShowNeedInfor( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
 		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
 		String needName = request.getParameter("needName");
 		BsUserInfor user = context.getUserInfo();
 		BsNeedInfor req = new BsNeedInfor();
 		req.setProTeamNo(user.getProTeamNo());
 		if(StringUtil.isNotEmpty(needName)){
	 		req.setNeedName(needName);
	 		req.setNeedNo(needName);
 		}
		List<BsNeedInfor> needList = this.userNeedService.selectNeedInfor(req);
		request.setAttribute("needList", needList);
		return "frame/html/need/showNeedInfor";
	}
	
	/**
	 * 需求新增功能
	 * @param request
	 * @param response
	 * @throws JTransException
	 * @throws JSystemException
	 */
	@RequestMapping("/page/need/addNeedInfor.do")
	public void addNeedInfor( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
 		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		//1、判断日期格式和工时是否合法。
 		
 		String reg = "^[0-9]+(.[0-9]+)?$";
		if(!req.getNeedTime().matches(reg)){
			throw new  JTransException("1001","你又乱填数字了哦，工时必须是数字！");
 		} 
 		//2、判断一个项目组一个需求数据唯一
   		List<BsNeedInfor> needList = this.userNeedService.selectNeedInforByNeedNoAndTeamNo(req);
  		if(needList.size()>0){
  			throw new  JTransException("1001","需求编号:"+req.getNeedNo()+"在该项目组中已经存在了！");
  		} 
  		//3、判断需求计划日期符合顺序
  		if(req.getNeed_Brewing().compareTo(req.getNeed_Analysis())>0&&(StringUtil.isNotEmpty(req.getNeed_Analysis()))){
  			throw new  JTransException("1001","分析时间必须在酝酿时间后面！");
  		} 
  		if(req.getNeed_Analysis().compareTo(req.getNeed_Confirm())>0&&(StringUtil.isNotEmpty(req.getNeed_Confirm()))){
  			throw new  JTransException("1001","确认时间必须在分析时间后面！");
  		} 
  		if(req.getNeed_Confirm().compareTo(req.getNeed_Review())>0&&(StringUtil.isNotEmpty(req.getNeed_Review()))){
  			throw new  JTransException("1001","评审时间必须在确认时间后面！");
  		} 
  		if(req.getNeed_Review().compareTo(req.getTechnical_Review())>0&&(StringUtil.isNotEmpty(req.getTechnical_Review()))){
  			throw new  JTransException("1001","技术评审时间必须在需求评审时间后面！");
  		} 
  		if(req.getTechnical_Review().compareTo(req.getDevelop_Joint())>0&&(StringUtil.isNotEmpty(req.getDevelop_Joint()))){
  			throw new  JTransException("1001","联调时间必须在技术评审时间后面！");
  		} 
  		if(req.getDevelop_Joint().compareTo(req.getSit_Test())>0&&(StringUtil.isNotEmpty(req.getSit_Test()))){
  			throw new  JTransException("1001","sit时间必须在联调时间后面！");
  		} 
  		if(req.getSit_Test().compareTo(req.getUat_Test())>0&&(StringUtil.isNotEmpty(req.getUat_Test()))){
  			throw new  JTransException("1001","uat时间必须在sit时间后面！");
  		} 
  		if(req.getUat_Test().compareTo(req.getNeed_Online())>0&&(StringUtil.isNotEmpty(req.getNeed_Online()))){
  			throw new  JTransException("1001","上线时间必须在uat时间后面！");
  		}

 		BsNeedInfor record = new BsNeedInfor();
 		record.setRouid(JRandomUtil.getUUID());
  		record.setNeedNo(req.getNeedNo());
 		record.setNeedTime(req.getNeedTime()); 
 		record.setProTeamNo(req.getProTeamNo());
 		record.setNeedName(req.getNeedName());
 		record.setContractNo(req.getContractNo());
 		record.setContractId(req.getContractId());
 		record.setCreateDate( DateUtil.getSystemTimeBySomeFormat("yyyyMMdd"));
 		record.setNow_Stage(req.getNow_Stage());
 		BsNeedStage emm= new BsNeedStage();
 		emm.setRouid(JRandomUtil.getUUID());
 		emm.setBack_Review(req.getBack_Review());
 		emm.setDevelop_Joint(req.getDevelop_Joint());
 		emm.setNeed_Analysis(req.getNeed_Analysis());
 		emm.setNeed_Brewing(req.getNeed_Brewing());
 		emm.setNeed_Confirm(req.getNeed_Confirm());
 		emm.setNeed_Online(req.getNeed_Online());
 		emm.setNeed_Review(req.getNeed_Review());
 		emm.setBack_Review_Old(req.getBack_Review());
 		emm.setDevelop_Joint_Old(req.getDevelop_Joint());
 		emm.setNeed_Analysis_Old(req.getNeed_Analysis());
 		emm.setNeed_Brewing_Old(req.getNeed_Brewing());
 		emm.setNeed_Confirm_Old(req.getNeed_Confirm());
 		emm.setNeed_Online_Old(req.getNeed_Online());
 		emm.setNeed_Review_Old(req.getNeed_Review());
 		emm.setNeedId(record.getRouid());
 		emm.setNeedNo(record.getNeedNo());
 		emm.setSit_Test(req.getSit_Test());
 		emm.setTechnical_Review(req.getTechnical_Review());
 		emm.setUat_Test(req.getUat_Test());
 		emm.setSit_Test_Old(req.getSit_Test());
 		emm.setTechnical_Review_Old(req.getTechnical_Review());
 		emm.setUat_Test_Old(req.getUat_Test());
 		emm.setNeed_State("00");
 		emm.setProTeamNo(req.getProTeamNo());
 		emm.setNeedName(req.getNeedName());
 		//00表示未审核
 		if(req.getState()!=null) {
 			record.setState(req.getState());
 		}else {
 		record.setState("00");}
 		//发送审核通知给团队经理
 		//获取登录用户的名称
 		record.setSign("0");
 		Object obj = request.getSession().getAttribute("loginUserName");
 		batch.sendAddNeedApplyToGroupUser(obj == null?"":obj.toString(), req.getProTeamNo());
 		
 		userNeedService.addNeedInfor(record);
 		//if(userNeedService.selectBsNeedStage(emm).size()>0) {
 			//userNeedService.updateBsNeedStage(emm);
 		//}else {
 			userNeedService.insertBsNeedStage(emm);
 		//}
 		Map rspModel = new HashMap();
		context.buildAppResponse(rspModel);
	}
	
	
	
	/**
	 * 根据needId查询需求计划明细
	 * 
	 * @param request
	 * @param response
	 * @param userNo
	 * @return
	 * @throws JTransException
	 * @throws JSystemException
	 */
	@RequestMapping("/page/main/{rouid}/StageByNeedId.do")
	public String StageByNeedId(HttpServletRequest request, HttpServletResponse response,
			@PathVariable String rouid) throws JTransException, JSystemException {
		BsNeedStage req =new BsNeedStage();
		req.setNeedId(rouid);
		List<BsNeedStage> InfoList = userNeedService.selectBsNeedStage(req);
		request.setAttribute("InfoList", InfoList);
		return "main/report/StageMx";
	}
	
	
	/**
	 * 根据needId查询需求计划修改明细
	 * 
	 * @param request
	 * @param response
	 * @param userNo
	 * @return
	 * @throws JTransException
	 * @throws JSystemException
	 */
	@RequestMapping("/page/main/{rouid}/StageByupdate.do")
	public String StageByupdate(HttpServletRequest request, HttpServletResponse response,
			@PathVariable String rouid) throws JTransException, JSystemException {
		BsNeedStage req =new BsNeedStage();
		req.setNeedId(rouid);
		List<BsNeedStage> InfoList = userNeedService.selectBsNeedStage(req);
		request.setAttribute("InfoList", InfoList);
		return "main/report/StageUpdateMx";
	}
	
	
	/**
	 * 修改需求功能 
	 */
	@RequestMapping("/page/need/updateNeedInfor.do")
	public void updateNeedInfor( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		//根据rouid 修改需求的名称、需求编号、需求评估工时
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
		this.userNeedService.updateNeedInforById(req);
		
		this.userNeedService.updateNeedNoRelByNeedId(req);
		Map rsModel = new HashMap();
		context.buildAppResponse(rsModel);
	}
	

	
	/**
	 * 查询登陆用户所属需求功能列表 
	 */
	@RequestMapping("/page/need/searchNeedInfor.do")
	public void searchNeedInfor( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsUserInfor user = context.getUserInfo();
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		req.setProTeamNo(user.getProTeamNo());
		List<BsNeedInfor> needList = this.userNeedService.selectNeedInfor(req);
		Map rsModel = new HashMap();
		rsModel.put("needList", needList);
 		context.buildAppResponse(rsModel);
	}
	
	
	
	@RequestMapping("/page/main/Conversion.do")
	public void NeedConversion(HttpServletRequest request, HttpServletResponse response
			) throws JTransException, JSystemException {
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);	
		List<NeedConversion> needList = this.userNeedService.selectConversion();
		String re=needList.get(0).getConversion();
		context.buildAppResponse(re);
	}
	
	
	
	
	
	
	/**
	 * 查询转化率报表
	 */
	@RequestMapping("/page/main/NeedConversion.do")
	public void searchNeedConversion( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
		NeedConversion req = context.obtainReqModel(NeedConversion.class);
        
		List<NeedConversion> needList = this.userNeedService.selectNeedConversion(req);
		Map rsModel = new HashMap();
		rsModel.put("needList", needList);
	/*	if(needList.size()>0) {
		String re=needList.get(0).getConversion();
		rsModel.put("re", re);
		}*/
 		context.buildAppResponse(rsModel);
	}
	
	
	/**
	 * 查询所选项目组所属需求功能列表 
	 */
	@RequestMapping("/page/need/searchNeedInforDetail.do")
	public void searchNeedInforDetail( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		String endRow = ((Integer.parseInt(req.getStartRow()))+(Integer.parseInt(req.getPageSize())))+"";
 		req.setEndRow(endRow);
		List<BsNeedInfor> needList = this.userNeedService.selectNeedInforDetailPage(req);
		int count = this.userNeedService.selectNeedInforDetailPageCount(req);
		Map rsModel = new HashMap();
		rsModel.put("count", count);
  		rsModel.put("needList", needList);
 		context.buildAppResponse(rsModel);
	}
	
	
	/**
	 * 查询所选项目组目标列表 
	 */
	@RequestMapping("/page/main/goal.do")
	public void searchgoal( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
		BsGoal req = context.obtainReqModel(BsGoal.class);
		List<BsGoal> needList = this.userNeedService.selectteamgoal(req);
 		context.buildAppResponse(needList);
	}
	
	/**
	 * 查询端对端
	 */
	@RequestMapping("/page/main/selectFacetoFace.do")
	public void selectFacetoFace( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		FaceToFace req = context.obtainReqModel(FaceToFace.class);
 		String endRow = ((Integer.parseInt(req.getStartRow()))+(Integer.parseInt(req.getPageSize())))+"";
 		req.setEndRow(endRow);
		List<FaceToFace> needList = this.userNeedService.selectFacePage(req);
		int count = this.userNeedService.selectFaceCount(req);
		Map rsModel = new HashMap();
		rsModel.put("count", count);
  		rsModel.put("needList", needList);
 		context.buildAppResponse(rsModel);
	}
	
	/**
	 * 端对端【导出】
	 */
	@RequestMapping("/page/main/doExcelFacetoFace.do")
	public void doExcelFacetoFace(HttpServletRequest request, HttpServletResponse response)
			throws JTransException, JSystemException {
		JAppContext context = serviceFactory.buildAppContextNoUser(request, response);// 自动客户信息
		FaceToFace param = context.obtainReqModel(FaceToFace.class);

		List<FaceToFace> rsList = userNeedService.selectFace(param);
		String path = request.getServletContext().getRealPath("");// 获取项目动态绝对路径
		ExportDataUtil export = new ExportDataUtil();
		ExcleEntity entity = new ExcleEntity();
		entity.setTitle("端对端");
		entity.setFileName(DateUtil.getSystemTimeBySomeFormat(DateUtil.FMT_ALL) + ".xls");
		entity.setPath(path);
		Map<Object, String> headMap = new LinkedHashMap<Object, String>();
		headMap.put("needNo","需求编号");
		headMap.put("needName","需求名称");
		headMap.put("hfjl","干系人");
		headMap.put("proTeamName","需求来源方(首次录入项目组)");
		headMap.put("qdTEAM","渠道团队关联项目组");
		headMap.put("jcTEAM","基础团队关联项目组");
		headMap.put("zgTEAM","资管团队关联项目组");
		headMap.put("xdTEAM","信贷团队关联项目组");
		headMap.put("sjTEAM","数据团队关联项目组");
		headMap.put("minDATE","首次录入时间");
		headMap.put("maxDATE","最近录入时间");
		headMap.put("groupCount","关联团队数量");
		entity.setHeadMap(headMap);
		export.exportExcel(entity, rsList);
		context.buildAppResponse(entity);
	}
	
	
	
	/**
	 * 需求管理【导出】
	 */
	@RequestMapping("/page/main/doExcelNeedInfor.do")
	public void doReportCountExcelFile(HttpServletRequest request, HttpServletResponse response)
			throws JTransException, JSystemException {
		JAppContext context = serviceFactory.buildAppContextNoUser(request, response);// 自动客户信息
		BsNeedInfor param = context.obtainReqModel(BsNeedInfor.class);

		List<BsNeedInfor> rsList = userNeedService.selectNeedInforDetail(param);
		String path = request.getServletContext().getRealPath("");// 获取项目动态绝对路径
		ExportDataUtil export = new ExportDataUtil();
		ExcleEntity entity = new ExcleEntity();
		entity.setTitle("需求管理");
		entity.setFileName(DateUtil.getSystemTimeBySomeFormat(DateUtil.FMT_ALL) + ".xls");
		entity.setPath(path);
		Map<Object, String> headMap = new LinkedHashMap<Object, String>();
		headMap.put("needNo","需求编号");
		headMap.put("needName","需求名称");
		headMap.put("needTime","评估工时");
		headMap.put("renyue","人月");
		headMap.put("stage","最新报功阶段");
		headMap.put("state","需求状态");
		headMap.put("dateOfLine","上线日期");
		headMap.put("hfjl","行方经理");
		headMap.put("hfywry","行方业务人员");
		headMap.put("need_State","需求阶段");
		headMap.put("planStatus","规划状态");
		headMap.put("months","月份");
		headMap.put("contractApproval","合同批次");
		headMap.put("contractId","合同号");
		headMap.put("contractNo","产品编号");
		headMap.put("sale_Money","录入销售系统金额");
		entity.setHeadMap(headMap);
		export.exportExcel(entity, rsList);
		context.buildAppResponse(entity);
	}
	
	
	
	/**
	 * 转化率报表【导出】
	 */
	@RequestMapping("/page/main/doExcelNeedConversion.do")
	public void doExcelNeedConversion(HttpServletRequest request, HttpServletResponse response)
			throws JTransException, JSystemException {
		JAppContext context = serviceFactory.buildAppContextNoUser(request, response);// 自动客户信息
		NeedConversion param = context.obtainReqModel(NeedConversion.class);
		List<NeedConversion> rsList = userNeedService.selectNeedConversion(param);
		String re=rsList.get(0).getConversion();
		String path = request.getServletContext().getRealPath("");// 获取项目动态绝对路径
		ExportDataUtil export = new ExportDataUtil();
		ExcleEntity entity = new ExcleEntity();
		entity.setTitle("需求转化率"+re+"报表");
		entity.setFileName(DateUtil.getSystemTimeBySomeFormat(DateUtil.FMT_ALL) + ".xls");
		entity.setPath(path);
		Map<Object, String> headMap = new LinkedHashMap<Object, String>();
		headMap.put("proGroupName","团队");
		headMap.put("months","月份");
		headMap.put("goal","营收目标");
		headMap.put("onlineAccrualSchedule","应计划（上线）");
		headMap.put("onlineSchedule","计划（上线）");
		headMap.put("onlineRealitySchedule","实际（上线）");
		headMap.put("preonlineAccrualSchedule","应计划（待上线）");
		headMap.put("preonlineSchedule","计划（待上线）");
		headMap.put("preonlineRealitySchedule","实际（待上线）");
		headMap.put("devAccrualSchedule","应计划（正在开发）");
		headMap.put("devSchedule","计划（正在开发）");
		headMap.put("devRealitySchedule","实际（正在开发）");
		headMap.put("cardingAccrualSchedule","应计划（需求梳理）");
		headMap.put("cardingSchedule","计划（需求梳理）");
		headMap.put("cardingRealitySchedule","实际（需求梳理）");
		headMap.put("brewAccrualSchedule","应计划（需求酝酿）");
		headMap.put("brewSchedule","计划（需求酝酿）");
		headMap.put("brewRealitySchedule","实际（需求酝酿）");
		entity.setHeadMap(headMap);
		export.exportExcel(entity, rsList);
		context.buildAppResponse(entity);
	}
	
	
	
	
	
	/**
	 * 删除需求信息
	 */
	@RequestMapping("/page/need/{needId}/doDeleteNeed.do")
	public void doDeleteNeed( HttpServletRequest request,HttpServletResponse response,@PathVariable String needId ) throws JTransException, JSystemException{
		//根据rouid 删除需求信息
 		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		
 		this.userNeedService.deleteUserNeedInfor(needId);
 		Map rsModel = new HashMap();
 		context.buildAppResponse(rsModel);
	}
	
	/**
	 * 查下需求时间轴信息
	 */
	@RequestMapping("/page/need/selectNeedTime.do")
	public void selectNeedTime( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
  		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
  		List<BsNeedTime> needTimeList = this.userNeedService.selectNeedTimeList(context.getUserInfo());
  		Map rsModel = new HashMap();
  		rsModel.put("needTimeList", needTimeList);
 		context.buildAppResponse(rsModel);
	}
	
	@RequestMapping("/page/need/updateStateByRouid.do")
	@ResponseBody
	public String updateStateByRouid(HttpServletRequest request,HttpServletResponse response){
		String state = request.getParameter("state");
		String rouid = request.getParameter("rouid");
		if(state == null || "".equals(state) || rouid == null || "".equals(rouid)){
			return "{\"status\":\"faild\"}";
		}
		int row = this.userNeedService.updateStateByRouid(rouid, state);
		if(row == 0){
			return "{\"status\":\"faild\"}";
		}else{
			return "{\"status\":\"success\"}";
		}
	}
	
	//需求计划驳回
	@RequestMapping("/page/need/updateNeedStageByRouid.do")
	@ResponseBody
	public String updateNeedStageByRouid(HttpServletRequest request,HttpServletResponse response){
		String state = request.getParameter("state");
		String rouid = request.getParameter("rouid");
		BsNeedStage req =new BsNeedStage();
		req.setNeedId(rouid);
		req.setNeed_State(state);
		if(state == null || "".equals(state) || rouid == null || "".equals(rouid)){
			return "{\"status\":\"faild\"}";
		}
		this.userNeedService.updateBsNeedStageOld(req);
		int row = this.userNeedService.updateBsNeedStage(req);
		if(row == 0){
			return "{\"status\":\"faild\"}";
		}else{
			return "{\"status\":\"success\"}";
		}
	}
	//需求计划通过
	@RequestMapping("/page/need/passNeedStageByRouid.do")
	@ResponseBody
	public String passNeedStageByRouid(HttpServletRequest request,HttpServletResponse response){
		String state = request.getParameter("state");
		String rouid = request.getParameter("rouid");
		BsNeedStage req =new BsNeedStage();
		req.setNeedId(rouid);
		req.setNeed_State(state);
		if(state == null || "".equals(state) || rouid == null || "".equals(rouid)){
			return "{\"status\":\"faild\"}";
		}
		this.userNeedService.updateBsNeedStageNew(req);
		int row = this.userNeedService.updateBsNeedStage(req);
		if(row == 0){
			return "{\"status\":\"faild\"}";
		}else{
			return "{\"status\":\"success\"}";
		}
	}
	
	
	@RequestMapping("/page/need/selectNoPassNeedByRouid.do")
	public String selectNoPassNeedByRouid(HttpServletRequest request,HttpServletResponse response){
		String rouid = request.getParameter("rouid");
		List<BsNeedInfor> list = this.userNeedService.selectNoPassNeedByRouid(rouid);
		request.setAttribute("list", list);
		return "main/report/needPass";
	}

		/**
		 * 删除需求信息
		 */
		@RequestMapping("/page/need/{needId}/docloseNeed.do")
		public String docloseNeed( HttpServletRequest request,HttpServletResponse response,@PathVariable String needId ) throws JTransException, JSystemException{
			JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
	 		String needName = request.getParameter("needName");
	 		BsUserInfor user = context.getUserInfo();
	 		BsNeedInfor req = new BsNeedInfor();
	 		req.setProTeamNo(user.getProTeamNo());
	 		if(StringUtil.isNotEmpty(needName)){
		 		req.setNeedName(needName);
		 		req.setNeedNo(needName);
	 		}
			List<BsNeedInfor> needList = this.userNeedService.selectNeedInfor(req);
			request.setAttribute("needList", needList);
			return "page/base/dologin.do"; 
		}
		
		/**
	 * 修改监控 
	 */
	@RequestMapping("/page/need/{needId}/doUpdateJianKong.do")
	public String doUpdateJianKong( HttpServletRequest request,HttpServletResponse response ,@PathVariable String needId) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);//buildAppContextWithUser 自带客户信息.
		List<BsNeedInfor> needList = this.userInforService.selectByNeedId(needId);
 		request.setAttribute("needBean", needList.get(0));
		return "frame/html/need/updateJianKong";
	}
	
	/**
	 * 修改监控功能 
	 */
	@RequestMapping("/page/need/doUpdateJianKong.do")
	public void doUpdateJianKong( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		//根据rouid 修改需求的名称、需求编号、需求评估工时
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);		//buildAppContextWithUser 自带客户信息.
		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
		this.userNeedService.doUpdateJianKong(req);
		Map rsModel = new HashMap();
		context.buildAppResponse(rsModel);
	}
	
	/**
	 * 查询项目组本月营收 差额  报工异常人数 yf 
	 */
	@RequestMapping("/page/need/SelectThreeData.do")
	public void SelectThreeData( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		RpUserReportBean param=new RpUserReportBean();
 		param.setReportType("1");
 		param.setProTeamNo(req.getProTeamNo());
 		param.setProGroupNo(req.getProGroupNo());
 		List<BsNeedInfor> curMonthList =this.userNeedService.selectCurMonthList(req);
 		//查询当月报工异常的人员信息
 		List<RpUserReportBean> rsNoList = this.reportService.curMonthNoreportTask(param);
 		List list=new ArrayList<>();
 		if(curMonthList.size()>0){
 			for (BsNeedInfor BsNeedInfor : curMonthList) {
 				String goal="";
				String balance="";
				if(BsNeedInfor.getGoal()==null){
					goal="0";
				}else{
					goal=BsNeedInfor.getGoal();
				}
				if(BsNeedInfor.getYsx()==null){
					balance="0";
				}else{
					balance=BsNeedInfor.getYsx();
				}
 				list.add(BsNeedInfor.getGoal()+"万");
 				
 				list.add((Double.parseDouble(goal)-Double.parseDouble(balance))+"万");
 			}
 		}else{
 			list.add("暂无");
 			list.add("暂无");
 		}
 		list.add(rsNoList.size());
		context.buildAppResponse(list);
	}
	
	/**
	 * 查询团队本月营收 差额 超额项目组 滞后项目组 yf 
	 */
	@RequestMapping("/page/need/SelectFourData.do")
	public void SelectFourData( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		List<BsNeedInfor> needMList = this.userNeedService.selectGoalAndReality(req);
 		List<BsNeedInfor> curMonthList =this.userNeedService.selectAllTeamIncome(req);
 		List<BsProTeamInfor> teanList = this.teamService.searchProTeanListByGroupNo(req.getProGroupNo());
 		
        List list=new ArrayList<>();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");    
        String date=sdf.format(new java.util.Date()); 
        DecimalFormat    df   = new DecimalFormat("######0.00");  
        for (BsNeedInfor bsNeedInfor : needMList) {
			if(date.equals(bsNeedInfor.getMonths())){
				String goal="";
				String balance="";
				if(bsNeedInfor.getGoal()==null){
					goal="0";
				}else{
					goal=bsNeedInfor.getGoal();
				}
				if(bsNeedInfor.getYsx()==null){
					balance="0";
				}else{
					balance=bsNeedInfor.getYsx();
				}
				//本月营收目标
				 list.add(df.format(Double.parseDouble(goal)));
				//差额
				 list.add(df.format(Double.parseDouble(goal)-Double.parseDouble(balance)));
			
				
			}
		}
        int goodList=0;
        int badList=0;
        for (BsNeedInfor b : curMonthList) {
        	String goal="";
			String ysx="";
			if(b.getGoal()==null){
				//目标营收没数据
				goal="0";
			}else{
				goal=b.getGoal();
			}
			if(b.getTeamIncome()==null){
				ysx="0";
			}else{
				ysx=b.getTeamIncome();
			}
			if(Double.parseDouble(ysx)-Double.parseDouble(goal)>0){
				goodList+=1;
			}else if(Double.parseDouble(ysx)-Double.parseDouble(goal)<0){
				badList+=1;
			}
		}
        list.add(goodList);
        list.add(teanList.size()-goodList);
		context.buildAppResponse(list);
	}
	
	/**
	 * 查询项目组的目标营收和实际营收 yf 
	 */
	@RequestMapping("/page/need/selectGoalAndRealityTeam.do")
	public void selectGoalAndRealityTeam( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		List<BsNeedInfor> needMList = this.userNeedService.selectGoalAndRealityTeam(req);
		context.buildAppResponse(needMList);
	}
	
	/**
	 * 查询各团队的目标营收和实际营收 yf 
	 */
	@RequestMapping("/page/need/selectGoalAndReality.do")
	public void selectGoalAndReality( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		List<BsNeedInfor> needMList = this.userNeedService.selectGoalAndReality(req);
		context.buildAppResponse(needMList);
	}
	
	
	/**
	 * 查询软件部本月营收 差额 超额团队 滞后团队
	 */
	@RequestMapping("/page/need/SelectFourFour.do")
	public void SelectFourFour( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		List<BsNeedInfor> needMList = this.userNeedService.selectGoalAndGroup();
 		List<BsNeedInfor> curMonthList =this.userNeedService.selectAllGroupIncome();
 		
        List list=new ArrayList<>();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");    
        String date=sdf.format(new java.util.Date()); 
        DecimalFormat    df   = new DecimalFormat("######0.00");  
        for (BsNeedInfor bsNeedInfor : needMList) {
			if(date.equals(bsNeedInfor.getMonths())){
				String goal="";
				String balance="";
				if(bsNeedInfor.getGoal()==null){
					goal="0";
				}else{
					goal=bsNeedInfor.getGoal();
				}
				if(bsNeedInfor.getBalance()==null){
					balance="0";
				}else{
					balance=bsNeedInfor.getBalance();
				}
				//本月营收目标
				 list.add(df.format(Double.parseDouble(goal)));
				//差额
				 list.add(df.format(Double.parseDouble(balance)));
			
				
			}
		}
        int goodList=0;
        int badList=0;
        for (BsNeedInfor b : curMonthList) {
        	String goal="";
			String ysx="";
			if(b.getGoal()==null){
				//目标营收没数据
				goal="0";
			}else{
				goal=b.getGoal();
			}
			if(b.getTeamIncome()==null){
				ysx="0";
			}else{
				ysx=b.getTeamIncome();
			}
			if(Double.parseDouble(ysx)-Double.parseDouble(goal)>0){
				goodList+=1;
			}else if(Double.parseDouble(ysx)-Double.parseDouble(goal)<0){
				badList+=1;
			}
		}
        list.add(goodList);
        list.add(badList);
		context.buildAppResponse(list);
	}
	
	
	/**
	 * 查询各团队的目标营收和实际营收 
	 */
	@RequestMapping("/page/need/selectGoalAndGroup.do")
	public void selectGoalAndGroup( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		List<BsNeedInfor> needMList = this.userNeedService.selectGoalAndGroup();
		context.buildAppResponse(needMList);
	}
	
	
	/**
	 * 查询团队中各项目组当月实际营收 yf 
	 */
	@RequestMapping("/page/need/selectAllTeamIncome.do")
	public void selectAllTeamIncome( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		List<BsNeedInfor> needMList = this.userNeedService.selectAllTeamIncome(req);
		context.buildAppResponse(needMList);
	}
	
	
	/**
	 * 查询各团队当月实际营收
	 */
	@RequestMapping("/page/need/selectAllGroupIncome.do")
	public void selectAllGroupIncome( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		List<BsNeedInfor> needMList = this.userNeedService.selectAllGroupIncome();
		context.buildAppResponse(needMList);
	}
	
	
	/**
	 * 查询软件部汇总 
	 */
	@RequestMapping("/page/need/SelectSoftwareSummary.do")
	public void selectSoftwareSummary( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		List<BsNeedInfor> needMList = this.userNeedService.selectSoftwareSummary(req);
		context.buildAppResponse(needMList);
	}
	/**
	 * 查询长沙银行汇总 
	 */
	@RequestMapping("/page/need/SelectBankSummary.do")
	public void selectBankSummary( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
		
		List<BsNeedInfor> needSumList = this.userNeedService.selectBankSummary();
		
		context.buildAppResponse(needSumList);
	}
	/**
	 * 查询长沙银行分解 
	 */
	@RequestMapping("/page/need/SelectBankResolve.do")
	public void selectBankResolve( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextNoUser(request,response);
 		BsNeedInfor req = context.obtainReqModel(BsNeedInfor.class);
 		String endRow = ((Integer.parseInt(req.getStartRow()))+(Integer.parseInt(req.getPageSize())))+"";
 		req.setEndRow(endRow);
		List<BsNeedInfor> needList = this.userNeedService.selectBankResolvePage(req);
		int count = this.userNeedService.selectBankResolvePageCount(req);
		Map rsModel = new HashMap();
		rsModel.put("count", count);
  		rsModel.put("needList", needList);
 		context.buildAppResponse(rsModel);
	}
	
	/**
		 * 下载监控表 
		 * @throws IOException 
		 */
		@RequestMapping("/page/main/JianKongLoad.do")
		public void JianKongLoad(HttpServletRequest request, HttpServletResponse response)
				throws JTransException, JSystemException {
			JAppContext context = serviceFactory.buildAppContextNoUser(request, response);// 自动客户信息
			BsNeedInfor param = context.obtainReqModel(BsNeedInfor.class);
			String path = request.getServletContext().getRealPath("");// 获取项目动态绝对路径
			ExportDataUtil excel = new ExportDataUtil();
			ExcleEntity excleBean = new ExcleEntity();
			excleBean.setTitleArr(new String[] {"各团队明细表","软件部汇总表","各团队汇总表"});
			excleBean.setFileName(DateUtil.getSystemTimeBySomeFormat(DateUtil.FMT_ALL) + "监控表.xls");
			excleBean.setPath(path);
			List headList = new ArrayList();
			Map<Object, String> headMap1 = new LinkedHashMap<Object, String>();
			headMap1.put("proGroupName","团队名称");
			headMap1.put("needNo","需求编号");
			headMap1.put("needName","需求名称");
			headMap1.put("team_manger","公司经理");
			headMap1.put("hfjl","行方经理");
			headMap1.put("hfywry","行方业务人员");
			headMap1.put("gscyry","公司参与人员");
			headMap1.put("stage","状态");
			headMap1.put("planStatus","规划状态");
			headMap1.put("createDate","开始日期");
			headMap1.put("dateOfLine","上线日期");
			headMap1.put("months","月份");
			headMap1.put("needTime","评估工时");
			headMap1.put("sjxhrt","实际消耗人天");
			headMap1.put("lastweek","截至上周投入人天");
			headMap1.put("weekRt","本周投入人天");
			headMap1.put("yj","是否预警");
			headMap1.put("wt","每日问题反馈");
			headMap1.put("contractApproval","合同批次");
			headList.add(headMap1);
			Map<Object, String> headMap2 = new LinkedHashMap<Object, String>();
			headMap2.put("proGroupName","团队名称");
			headMap2.put("mb","目标");
			headMap2.put("months","月份");
			headMap2.put("goal","营收目标");
			headMap2.put("ysx","已完成");
			headMap2.put("ypgwsx","已评估未上线");
			headMap2.put("balance","差额");
			headMap2.put("ygj","月估计还能完成");
			headMap2.put("ylx","已立项");
			headMap2.put("yxrw","已下任务单");
			headMap2.put("wlx","未立项");	
			headList.add(headMap2);
			Map<Object, String> headMap = new LinkedHashMap<Object, String>();
			headMap.put("proGroupName","团队名称");
			headMap.put("yxrw","已下任务单");
			headMap.put("ylx","已立项");
			headMap.put("wlx","未立项");
			headMap.put("yggh","已过评审规划");
			headMap.put("ysx","已上线");
			headMap.put("ysxx","已上线下任务单");
			headMap.put("ysxw","已上线无任务单");
			headList.add(headMap);
			excleBean.setHeadList(headList);
			List<BsNeedInfor> needMList = this.userNeedService.selectSoftwareSummary(param);
			List<BsNeedInfor> needList = this.userNeedService.selectBankResolve(param);
			List<BsNeedInfor> needSumList = this.userNeedService.selectBankSummary();
			List[]reportListArr=new List[]{needList,needMList,needSumList};
			//List[] reportListArr = new ArrayList[]{needList,needMList,needSumList};
			excel.exportExcelMoreSheet(excleBean, reportListArr);
			context.buildAppResponse(excleBean);

		}
		
		
		
		
		
		
}
